<?php
	class Orangtua_model extends Model{
		function Orangtua_model(){
			parent::Model();
		}
        
        function list_data($nip="",$where="", $order="", $ro=false) {     
        	if ($nip=="") {
        		return "";
        	} else {
                $this->db->where(array('nip' => $nip));
                $this->db->or_where(array('nip_baru' => $nip));
        	}
        	
            if ($where!='') {
                $this->db->where($where);
            }
            if ($order == "") {
                $this->db->order_by('nip asc');
                $this->db->order_by('nip_baru asc');
            } else {
                $this->db->order_by($order);
            }
            $this->db->from('pegawai');
            $q = $this->db->get();

            $s = "
              <table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"tbl\">
                <thead>
                  <tr>
                  
                    ";
            if ($ro==false) {
                $s .= "";
            }
            $s .= "</tr></thead>";
			$i = 1;

            $this->load->model('Datum_model');
            foreach($q->result() as $row) {
                
                $this->db->where(array('id_pegawai' => $row->idspg_pegawai));                
                $q1 = $this->db->get('orang_tua');
                if ($q1->num_rows() > 0) {
                	foreach ($q1->result() as $row1) {
		               
		                
		                $s .= "
                      <tbody id=\"row-".$row1->id_orang_tua."\">  
		              <tr>
		                <th >Nama Ayah</th><td width=\"70%\" class=\"event\" colspan='2'>".$row1->nama_ayah."</td>
                      </tr>
                      <tr>
		                <th >Tempat Lahir</th><td class=\"event\" colspan='2'>".$row1->tmp_lahir_ayah."</td>
                      </tr>
                      <tr>  
		                <th >Tgl Lahir</th><td class=\"event\" colspan='2'>".YMD2DMY(trimTime($row1->tgl_lahir_ayah), TGL_SEPARATOR)."</td>
                      </tr>
                      <tr>
		                <th >Pekerjaan</th><td class=\"event\" colspan='2'>".$row1->pekerjaan_ayah."</td>
                      </tr>
                      <tr>
                        <th >Nama Ibu</th><td class=\"event\" colspan='2'>".$row1->nama_ibu."</td>
                      </tr>
                      <tr>  
                        <th >Tempat Lahir</th><td class=\"event\" colspan='2'>".$row1->tmp_lahir_ibu."</td>
                      </tr>
                      <tr>
                        <th >Tgl Lahir</th><td class=\"event\" colspan='2'>".YMD2DMY(trimTime($row1->tgl_lahir_ibu), TGL_SEPARATOR)."</td>
                      </tr>
                      <tr>
                        <th >Pekerjaan</th><td class=\"event\" colspan='2'>".$row1->pekerjaan_ibu."</td>
                      </tr>
                      <tr>
                        <th >Alamat</th><td class=\"event\" colspan='2'>".$row1->alamat."</td>
                      </tr>
                      <tr>
                        <th >No. Telepon</th><td class=\"event\" colspan='2'>".$row1->no_telp."</td>
                      </tr>
                      <tr>
                        <th >Kota/Kabupaten</th><td class=\"event\" colspan='2'>".$row1->kab_kota."</td>
                      </tr>
                      <tr>
                        <th >Kode Pos</th><td class=\"event\" colspan='2'>".$row1->kodepos."</td>
                      </tr>
                      <tr>
                        ";
		                if ($ro==false) {
		                    $s .= " <th> Aksi </th>
		                    <td><div align='center'> <a href='".base_url()."index.php/orang_tua/form_edit/".$row1->id_orang_tua."' title=\"Ubah Data\" class=\"edit\"><img src='".base_url()."images/edit.gif' border='0'></a></div></td>";
                            //if($this->input->post('page'))   
		                    $s .= "<td><div align='center'><a href=\"javascript:deleteRow(".$row1->id_orang_tua.")\"><img src='".base_url()."images/del.gif' border='0'></a></div></td>";
		                }
		                $s .= "
		              </tr></tbody>";
		
		                $i++;
                	} //foreach
                } else {
                	continue;
                }

            }
            $s .= "</table>";
            return $s;
        }

        function entry_data($form_id, $form_action, $arr=array()) {
            if (isset($arr['tgl_lahir_ayah'])) {
                $a = explode(TGL_SEPARATOR, trimTime($arr['tgl_lahir_ayah']));
                $d = $a[2] * 1;
                $m = $a[1] * 1;
                $y = $a[0];
            } else {
                $d = date("j");
                $m = date("n");
                $y = date("Y");
            }
            if (isset($arr['tgl_lahir_ibu'])) {
                $a = explode(TGL_SEPARATOR, trimTime($arr['tgl_lahir_ibu']));
                $dm = $a[2] * 1;
                $mm = $a[1] * 1;
                $ym = $a[0];
            } else {
                $dm = date("j");
                $mm = date("n");
                $ym = date("Y");
            }
            
            $ret = "
            <form id=\"".$form_id."\" action=\"".$form_action."\" method=\"post\">
            <fieldset >
            <table class=\"formTabel\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\">
              <tr>
                <td class=\"kolom\" valign=\"top\">NIP</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"nip\" id=\"nip\" value=\"".(isset($arr['nip'])?$arr['nip']:$this->session->userdata('nip'))."\" /></td>
              </tr>  
              <tr>
                <td class=\"kolom\" valign=\"top\">Nama Ayah</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[nama_ayah]\" size=\"50\" value=\"".(isset($arr['nama_ayah'])?$arr['nama_ayah']:"")."\" /></td>
              </tr>
              <tr>
                <td class=\"kolom\" valign=\"top\">Tempat Lahir</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[tmp_lahir_ayah]\" size=\"50\" value=\"".(isset($arr['tmp_lahir_ayah'])?$arr['tmp_lahir_ayah']:"")."\" /></td>
              </tr>
              <tr>
                  <td class='fieldname' valign=\"top\">Tanggal Lahir Ayah</td>
                  <td valign=\"top\">:</td>
                  <td>".combo_tanggal('d',$d,'')."-".
                      combo_bulan('m',$m,'').
                      "-<input name='y' id='y' type='text' size='6' value='$y'/>
                        <a href=\"#\" id=\"date-pick\">Pilih Tanggal</a>       
                  </td>
              </tr>
              <tr>
                <td class=\"kolom\" valign=\"top\">Pekerjaan</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[pekerjaan_ayah]\" size=\"50\" value=\"".(isset($arr['pekerjaan_ayah'])?$arr['pekerjaan_ayah']:"")."\" /></td>
              </tr>
              
              <tr>
                <td class=\"kolom\" valign=\"top\">Status Tunjangan</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[tmp_lahir_ayah]\" size=\"50\" value=\"".(isset($arr['tmp_lahir_ayah'])?$arr['tmp_lahir_ayah']:"")."\" /></td>
              </tr>
              <tr>
                <td class=\"kolom\" valign=\"top\">Pekerjaan</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[pekerjaan_ayah]\" size=\"50\" value=\"".(isset($arr['pekerjaan_ayah'])?$arr['pekerjaan_ayah']:"")."\" /></td>
              </tr>
              <tr>
                <td class=\"kolom\" valign=\"top\">Nama Ibu</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[nama_ibu]\" size=\"50\" value=\"".(isset($arr['nama_ibu'])?$arr['nama_ibu']:"")."\" /></td>
              </tr>
              <tr>
                <td class=\"kolom\" valign=\"top\">Tempat Lahir</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[tmp_lahir_ibu]\" size=\"50\" value=\"".(isset($arr['tmp_lahir_ibu'])?$arr['tmp_lahir_ibu']:"")."\" />
                </td>
              </tr>
              <tr>
                  <td class='fieldname' valign=\"top\">Tanggal Lahir Ibu</td>
                <td valign=\"top\">:</td>
                <td>".combo_tanggal('dm',$dm,'')."-".
                      combo_bulan('mm',$mm,'').
                      "-<input name='ym' id='ym' type='text' size='6' value='$ym'/>
                        <a href=\"#\" id=\"date-pick\">Pilih Tanggal</a>       
                </td>
              </tr>
              
              <tr>
                <td class=\"kolom\" valign=\"top\">Pekerjaan</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[pekerjaan_ibu]\" size=\"50\" value=\"".(isset($arr['pekerjaan_ibu'])?$arr['pekerjaan_ibu']:"")."\" />
                </td>
              </tr>
              <tr>
                <td class=\"kolom\" valign=\"top\">Alamat</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[alamat]\" size=\"50\" value=\"".(isset($arr['alamat'])?$arr['alamat']:"")."\" />
                </td>
              </tr>
              <tr>
                <td class=\"kolom\" valign=\"top\">No Telepon</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[no_telp]\" size=\"50\" value=\"".(isset($arr['no_telp'])?$arr['no_telp']:"")."\" />
                </td>
              </tr>
              <tr>
                <td class=\"kolom\" valign=\"top\">Kota/Kabupaten</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[kab_kota]\" size=\"50\" value=\"".(isset($arr['kab_kota'])?$arr['kab_kota']:"")."\" />
                </td>
              </tr>
              <tr>
                <td class=\"kolom\" valign=\"top\">Kode Pos</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[kodepos]\" size=\"5\" value=\"".(isset($arr['kodepos'])?$arr['kodepos']:"")."\" />
                </td>
              </tr>
              <tr>
                <td valign=\"top\">&nbsp;</td>
                <td valign=\"top\">&nbsp;</td>
                <td valign=\"top\">
                  <input class=\"tombol\" type=\"button\" name=\"btn_kembali\" id=\"btn_kembali\" value=\"<< Kembali\" />
                  <input class=\"tombol\" type=\"submit\" name=\"button\" id=\"button\" value=\"   Simpan   \" />
                </td>
              </tr>
            </table>
            </fieldset>
            </form>
              ";
            
            return $ret;
        }

        function simpan($arr, $is_update=false, $id='') {
            if (!$is_update) {
                $this->db->insert('orang_tua', $arr);
                
            } else {
                $this->db->where('id_orang_tua', $id);
                $this->db->update('orang_tua', $arr);
            }
        }
        
	}
?>